/* 
 * File:   lcd_driver.c
 * Author: rafael
 *
 * Created on 1 de Setembro de 2010, 16:42
 */

#include <stdio.h>
//#include <stdlib.h>
#include "lcd_driver.h"

/*
 * 
 */
/*
void test_sync() {
  int i = 0;
  *ctrl_reg = 0x100;
  for (i = 0;i<=30;i++){
    printf("sync: %d\n", *ctrl_reg);
  }
}*/

unsigned int get_data(){
	return (unsigned int) *ctrl_reg;
}

void send_data(char data){
	*ctrl_reg = data | 0x100;
}

void send_command(char data){
	*ctrl_reg = data;// & 0xff;
}

void drv_reset(){
	send_command(1);
}

void drv_init() {
	send_data(0);
	drv_reset();
	send_command(17);
	send_command(3);
	send_command(19);
	send_command(33);
}

void drv_setcontrast(char data){
	send_command(0x25);
	send_data(data);
}

void drv_turn_on(){
	send_command(0x29);
}

void drv_turn_off(){
	send_command(0x28);
}

void drv_send_data(char data){
    if (get_data() != 44){
    	send_command(44);
    }
    send_data(data);
}

void drv_sleep_in(){
	send_command(0x10);
}

void drv_sleep_out(){
	send_command(0x11);
}

void drv_partial_mode(){
	send_command(0x12);
}

void drv_normal_mode(){
	send_command(0x13);
}

void drv_inversion_on(){
	send_command(0x21);
}

void drv_vert_scroll(char data){
	send_command(0x33);
	send_data(data);
}

void finalize(){
	send_command(0xff);
}

/*
 *enum _display_commands {ON=0x29, OFF=0x28, DATA_WRITE=0x2C, RST=0x01, SLEEP_OUT=0x11, SLEEP_IN=0x10,
							PARTIAL_MODE=0x12, NORMAL_MODE=0x13, INVERSION_ON=0x21, INVERSION_OFF=0x20,
							NORMAL_MEM_ORDER=0xBA, CHANGED_MEM_ORDER=0xBB, SETCON=0x25, VERT_SCROLL = 0x33, SET_CONTRAST = 0x19} display_cmds;
*/
